<template>
  <vue-content>
    <vue-header>
      <div style="float:right">
        <vue-header-form class="headerFrom">
          <el-form :inline="true" :model="formFilter" ref="formFilter">
            <el-form-item>
              <el-button
                type="info"
                @click="couponPage()">核销订单</el-button>
            </el-form-item>
          </el-form>
        </vue-header-form>
      </div>
    </vue-header>
    <vue-body>
      <el-table
      	v-loading.body="loading"
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          prop="storeName"
          label="	店铺名称">
        </el-table-column>
        <el-table-column
          prop="name"
          label="	申请人名称">
        </el-table-column>
        <el-table-column
          prop="phone"
          label="	申请人手机号">
        </el-table-column>
        <el-table-column
          prop="applyDate"
          label="申请时间">
        </el-table-column>
        <el-table-column
          label="审核状态">
          <template slot-scope="scope">
            {{ scope.row.status | status }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200px">
          <template slot-scope="scope">
            <el-button-group>
            <el-button
              size="mini"
              :disabled="scope.row.status != '00'"
              @click="handleOpera( scope.row,'01', tableData)">通过</el-button>
            <el-button
              size="mini"
              :disabled="scope.row.status != '00'"
              @click="handleOpera( scope.row,'02', tableData)">不通过</el-button>
              </el-button-group>
          </template>
      </el-table-column>
      </el-table>
    </vue-body>
     <vue-footer style="padding: 5px 0;margin: 0 -5px;float:right;">
      <el-pagination
        :current-page.sync="currentPage"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="pageSize">
      </el-pagination>
    </vue-footer>
  </vue-content>
</template>

<script>
  import AuthStorage from '@/services/storage.js'
  import {queryStoreUser,operation} from '@/services/reports'
  import {RequestError} from '@/services/errors'
  import {deepClone} from '@/utilities/object'
  export default {
    name: 'sp-opera',
    components: {},
    data: () => ({
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      formFilter: {
      },
      loading: false,
      CategoryList:[],
      view: '',
      ifShow:false
    }),
    methods: {
      async loadData () {
        this.loading = true
        try {
          let data = await queryStoreUser(Object.assign({currentPage: this.currentPage},{perPage:10},this.formFilter))
          // debugger
          this.tableData = data.data
          this.pageSize = parseInt(data.totalResult)
        } catch (e) {
          if (e instanceof RequestError) {
            this.$alert(e.message, '提示', {
              type: 'error',
              confirmButtonText: '确定'
            })
          } else {
            throw e
          }
        }
        this.loading = false
      },
      async handleOpera (data,status) {
        try {
          await operation({applyNo:data.applyNo,status:status})
          this.$message({
            type: 'success',
            message: '成功'
          })
          this.loadData()
        } catch (e) {
          if (e instanceof RequestError) {
            this.$alert(e.message, '提示', {
              type: 'error',
              confirmButtonText: '确定'
            })
          } else {
            throw e
          }
        }
      },
      async couponPage (index, data) {
        this.$router.push({
          path: 'spOperation/verification', 
          name: 'verification',
          query: { 
          }
        })
      },
    },
    watch: {
      currentPage (newVal) {
        this.loadData(newVal)
      }
    },
    filters: {
      status (value) {
      	//发券途径
        return {'00': '待审核','01': '审核通过','02': '审核不通过'}[value]
      },
    },
    created () {
      this.loadData()
    }
  }
</script>
